/*
 * @lc app=leetcode.cn id=205 lang=typescript
 *
 * [205] 同构字符串
 */

// @lc code=start
function isIsomorphic(s: string, t: string): boolean {
    return isSameArray(replacer(s), replacer(t));
}

const isSameArray = (a: number[], b: number[]) => {
    return a.every((i, index) => {
        return i === b[index];
    });
};
const replacer = (s: string) => {
    const set: string[] = [];
    return s.split("").map((i) => {
        const index = set.indexOf(i);
        if (index === -1) {
            const newIndex = set.push(i);
            return newIndex;
        } else {
            return index;
        }
    });
};
// @lc code=end
